package sch.frog.behavioral.memento;

public class Caretaker {

    private Stack head = null;

    public void addMemento(Memento memento) {
        Stack stack = new Stack(memento);
        if(head == null){
            head = stack;
        }else{
            stack.setNext(head);
            head = stack;
        }
    }

    public Memento popMemento(){
        if(head != null){
            Memento memento = head.getMemento();
            head = head.getNext();
            return memento;
        }else{
            return null;
        }
    }

    private static class Stack{
        private Memento memento;

        private Stack next;

        public Stack(Memento memento){
            this.memento = memento;
        }

        public Memento getMemento() {
            return memento;
        }

        public void setMemento(Memento memento) {
            this.memento = memento;
        }

        public Stack getNext() {
            return next;
        }

        public void setNext(Stack next) {
            this.next = next;
        }
    }
}
